export default {

    state: {
        radarCollection: [],     // 记录存储所有的雷达
        radarAreaCollection: [], // 记录存储所有的雷达范围
        moveRadar: false,        // 是否移动雷达(鼠标移动时更改)
        radarId: 0,              // 记录当前移动的雷达的id(右键时添加)
        radarUI: false,          // 雷达UI
        areaPosition: {          //当前点击的雷达范围
            x1:2,y1:1,x2:1,y2:1,x3:1,y3:1,x4:1,y4:1},         
        
    },

    getters: {
        // 根据id获取radarCollection中的指定雷达
        searchRadar(state) {
            var radar;
            for(let i = 0; i<state.radarCollection.length; i++) {
                if(state.radarCollection[i].asset.extras[0].Id == state.radarId) {
                    radar = state.radarCollection[i]
                }
            }
            return radar
        },

        // 根据id获取radarAreaCollection中的指定雷达范围
        searchRadarArea(state) {
            var area;
            for(let i = 0; i<state.radarAreaCollection.length; i++) {
                if(state.radarCollection[i].asset.extras[0].Id == state.radarId) {
                    area = state.radarAreaCollection[i]
                }   
            }
            return area
        }
    },

    mutations: {
        // 添加雷达
        addRadar(state, data) {
            state.radarCollection.push(data)
        },

        // 删除雷达
        delRadar(state, data) {
            state.radarCollection[data].show = false;
            state.radarAreaCollection[data].show = false;
            state.radarCollection.splice(data, 1)
            state.radarAreaCollection.splice(data, 1)
        },

        // 添加雷达范围
        addArea(state, data) {
            state.radarAreaCollection.push(data)
        },

        // 更新雷达范围
        updateArea(state, data) {
            state.radarAreaCollection[data.areaIndex].show = false;
            state.radarAreaCollection[data.areaIndex] = data.newArea
        },

        // 雷达处于可以移动状态
        changeRadarstate(state, extras) {
            state.moveRadar = extras
        },

        // 记录点击的雷达id
        changeRadarId(state, id) {
            state.radarId = id
        },
        
        // 雷达UI界面
        showRadarUI(state, flag) {
            state.radarUI = flag
        },

        // 当前点击的雷达的范围
        addAreaPosition(state, data) {
            state.areaPosition = data
        },
    }
}